package com.springboot.last_experiment.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.springboot.last_experiment.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao extends BaseMapper<User> {
    @Select( "select * from user where openid=#{openid}")
    public User selectById(String openid);

    @Update("update user set " +
        "user_id=#{userId}," +
        "name=#{name}," +
        "role=#{role}," +
        "sex=#{sex}," +
        "picture=#{picture}," +
        "nick=#{nick}," +
        "address=#{address}," +
        "skey=#{skey}," +
        "is_resident=#{isResident}," +
        "is_lock=#{isLock}," +
        "status=#{status}," +
        "is_verify=#{isVerify}," +
        "phone=#{phone} where openid=#{openid}")
    public void update(User user);

    @Update("update user set is_lock=1 where openid = #{openid}")
    public void lockUser(String openid);
    @Update("update user set is_lock=0 where openid = #{openid}")
    public void unlockUser(String openid);

    @Update("update user set role=1 where openid = #{openid}")
    public void updateIns(String openid);
    @Update("update user set role=0 where openid = #{openid}")
    public void updateRes(String openid);
    @Select( "select  * from user where status=1")
    public List<User> selectWarn();

    @Select( "select  * from user where status=2")
    public List<User> selectDanger();

    @Select( "select  * from user")
    public List<User> selectAll();

    @Select("select * from user where skey=#{skey}")
    public User selectBySkey(String skey);

    @Select("select * from user where " +
        "user_id=#{key} " +
        " or name like '%${key}%'" +
        " or address like '%${key}%'")
    public List<User> getUserByKey(String key);

    @Update("update user set status=#{status} where openid = #{openid}")
    public void updateStatus(String openid,Integer status);

    @Update("update user set is_verify=1 where openid = #{openid}")
    public void updateCheck(String openid);

    @Delete("delete from user where openid = #{openid}")
    public void deleteUser(String openid);

}
